package com.xiangyueEducation.uploaderCloud.mq.batchImport;

import com.xiangyueEducation.uploaderCloud.mapper.UserMapper;
import com.xiangyueEducation.uploaderCloud.pojo.entity.User;
import com.xiangyueEducation.uploaderCloud.utils.JSONUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class BatchImportListener {
    @Resource(name = "ioPool")
    TaskExecutor executor;
    @Autowired
    JSONUtil jsonUtil;
    @Resource
    UserMapper userMapper;

    @RabbitListener(queues = "batchImport-queue")
    public void batchImport(String message){
        //导入到数据库
        executor.execute(() -> {
            userMapper.insert(jsonUtil.parseToObj(message.getBytes(), User.class));
            log.info("用户信息导入成功-----"+message);
        });

    }
}
